import request from '@/utils/request'

export function getEmployeeApi(params) {
  return request({
    url: '/sys/user',
    method: 'get',
    params
  })
}

export function excelExportApi() {
  return request({
    url: '/sys/user/export',
    method: 'get',
    // 改变接收数据的类型
    responseType: 'blob' // 使用blob接收二进制文件流
  })
}

export function getExportTemplateApi() {
  return request({
    url: '/sys/user/import/template',
    responseType: 'blob',
    method: 'get'
  })
}

export function upExcel(data) {
  return request({
    url: '/sys/user/import',
    method: 'post',
    data
  })
}

export function delEmployeeApi(i) {
  return request({
    url: `/sys/user/${i}`,
    method: 'delete'
  })
}

export function addEmployeeApi(data) {
  return request({
    url: '/sys/user',
    method: 'post',
    data
  })
}

export function getEmployeeDetail(id) {
  return request({
    url: `/sys/user/${id}`,
    method: 'get'
  })
}

export function updateEmployee(data) {
  return request({
    url: `/sys/user/${data.id}`,
    method: 'put',
    data
  })
}

export function getEmployeeRoleApi() {
  return request({
    url: '/sys/role/list/enabled'
  })
}

export function assignRoleApi(id, roleIds) {
  return request({
    url: '/sys/user/assignRoles',
    method: 'put',
    data: {
      id,
      roleIds
    }
  })
}
